package zmwxapplet

import (
	"github.com/gin-gonic/gin"
	"yundian/internel/app/dao/ticketdao"
	"yundian/internel/app/helper"
	"yundian/internel/app/helper/request"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
)

func GetTicketLineOrdersList(ctx *gin.Context) {
	memberId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetTicketLineOrdersListReq{}
	dingo.ErrorIf(ctx.ShouldBindQuery(param)).Unwrap()
	param.MemberId = memberId

	data := ticketdao.NewTicketDao().GetTicketLineOrdersList(param)
	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// 获取路线旅游图列表
func GetTicketLineList(ctx *gin.Context) {
	// 请求参数处理
	param := &request.BaseListReq{}
	dingo.ErrorIf(ctx.ShouldBindQuery(param)).Unwrap()

	data := ticketdao.NewTicketDao().GetTicketLineList(param)
	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

func GetTicketLineInfo(ctx *gin.Context) {
	// 请求参数处理
	param := &struct {
		Id int `json:"id" form:"id"`
	}{}
	dingo.ErrorIf(ctx.ShouldBindQuery(param)).Unwrap()

	data := ticketdao.NewTicketDao().GetTicketLineInfo(param.Id)

	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// 获取旅游美景图
func GetTicketTipsList(ctx *gin.Context) {
	// 请求参数处理
	param := &request.BaseListReq{}
	dingo.ErrorIf(ctx.ShouldBindQuery(param)).Unwrap()

	data := ticketdao.NewTicketDao().GetTicketTipsList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: 0,
		TotalPage:  0,
		Data:       data.Unwrap(),
	})(OK)
}
